package com.jishaokang.controller;

import com.jishaokang.base.Result;
import com.jishaokang.model.dto.Chapter;
import com.jishaokang.model.dto.Comment;
import com.jishaokang.service.ChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Created by NANA_Final on 2019/6/21.
 */
@RestController
@RequestMapping(value = "/api")
public class ChapterController {

    @Autowired
    private ChapterService chapterService;

    //----------------------------------------------
    @RequestMapping(value = "/all/chapter/selectChapterByCourseId",method = RequestMethod.POST)
    public Result selectChapterByCourseId(@RequestBody Chapter chapter) {
        return chapterService.selectChapterByCourseId(chapter);
    }

    @RequestMapping(value = "/all/chapter/selectChapterByChapterId",method = RequestMethod.POST)
    public Result selectChapterByChapterId(@RequestBody Chapter chapter) {
        return chapterService.selectChapterByChapterId(chapter);
    }

    @RequestMapping(value = "/user/chapter/selectRealChapterByChapterId",method = RequestMethod.POST)
    public Result selectRealChapterByChapterId(@RequestBody Chapter chapter) {
        return chapterService.selectRealChapterByChapterId(chapter);
    }


    //-------------------------------------------------------
    @RequestMapping(value = "/teacher/chapter/selectRealChapterByCourseId",method = RequestMethod.POST)
    public Result selectRealChapterByCourseId(@RequestBody Chapter chapter) {
        return chapterService.selectRealChapterByCourseId(chapter);
    }

    @RequestMapping(value = "/teacher/chapter/addChapter",method = RequestMethod.POST)
    public Result addChapter(@RequestBody Chapter chapter) {
        return chapterService.addChapter(chapter);
    }

    @RequestMapping(value = "/teacher/chapter/updateChapter",method = RequestMethod.POST)
    public Result updateChapter(@RequestBody Chapter chapter) {
        return chapterService.updateChapter(chapter);
    }

    @RequestMapping(value = "/teacher/chapter/uploadChapterVideo",method = RequestMethod.POST)
    public Result updateChapterVideo(@RequestParam String token,@RequestParam  int chapterId,@RequestParam(value = "chapterVideoFile", required = false) MultipartFile chapterVideoFile, HttpServletRequest request) throws IOException {
        return chapterService.updateChapterVideo(token,chapterId,chapterVideoFile,request);
    }

    @RequestMapping(value = "/teacher/chapter/deleteChapter",method = RequestMethod.POST)
    public Result teacherDeleteChapter(@RequestBody Chapter chapter) {
        return chapterService.deleteChapter(chapter);
    }

    //-----------------------------------------
    @RequestMapping(value = "/examiner/chapter/selectChapterByState",method = RequestMethod.POST)
    public Result selectChapterByState(@RequestBody Chapter chapter) {
        return chapterService.selectChapterByState(chapter);
    }

    @RequestMapping(value = "/examiner/chapter/updateChapterStateAllow",method = RequestMethod.POST)
    public Result updateChapterStateAllow(@RequestBody Chapter chapter,HttpServletRequest request) {
        return chapterService.updateChapterStateAllow(chapter,request);
    }

    @RequestMapping(value = "/examiner/chapter/updateChapterStateRefuse",method = RequestMethod.POST)
    public Result updateChapterStateRefuse(@RequestBody Chapter chapter) {
        return chapterService.updateChapterStateRefuse(chapter);
    }

    @RequestMapping(value = "/examiner/chapter/deleteChapter",method = RequestMethod.POST)
    public Result examinerDeleteChapter(@RequestBody Chapter chapter) {
        return chapterService.deleteChapter(chapter);
    }

}